package com.prs.crm.dao.oa.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.oa.CommentDao;
import com.prs.crm.domain.oa.Affiche;
import com.prs.crm.domain.oa.Announcement;
import com.prs.crm.domain.oa.AnnouncementReceive;
import com.prs.crm.domain.oa.Comment;
import com.prs.crm.domain.oa.MyFile;
import com.prs.crm.domain.oa.News;
import com.prs.crm.domain.oa.NewsReceive;
import com.prs.crm.domain.oa.Notice;
import com.prs.crm.domain.oa.NoticeAccept;
import com.prs.crm.domain.oa.PictureNews;
import com.prs.crm.domain.oa.PictureNewsReceive;

public class CommentDaoImpl  extends BaseDaoImpl<Comment> implements CommentDao{


	@Override
	public Comment getCommentByNews(News news) {
		Criteria criteria = this.getSession().createCriteria(Comment.class);
		criteria.add(Restrictions.eq("news", news));
		List<Comment> r= criteria.list();
		if(r.size()==0){
			return null;
		}else{
			return r.get(0);
		}
	}

	@Override
	public Comment getCommentByPicture(PictureNews pictureNews) {
		Criteria criteria = this.getSession().createCriteria(Comment.class);
		criteria.add(Restrictions.eq("pictureNews", pictureNews));
		List<Comment> r= criteria.list();
		if(r.size()==0){
			return null;
		}else{
			return r.get(0);
		}
	}

	@Override
	public Comment getCommentByAnnouncement(Announcement announcement) {
		Criteria criteria = this.getSession().createCriteria(Comment.class);
		criteria.add(Restrictions.eq("announcement", announcement));
		List<Comment> r= criteria.list();
		if(r.size()==0){
			return null;
		}else{
			return r.get(0);
		}
	}

	@Override
	public Comment getCommentByNotice(Notice notice) {
		Criteria criteria = this.getSession().createCriteria(Comment.class);
		criteria.add(Restrictions.eq("notice", notice));
		List<Comment> r= criteria.list();
		if(r.size()==0){
			return null;
		}else{
			return r.get(0);
		}
	}

	@Override
	public Comment getCommentByNotice(NewsReceive newsReceive) {
		Criteria criteria = this.getSession().createCriteria(Comment.class);
		criteria.add(Restrictions.eq("newsReceive", newsReceive));
		List<Comment> r= criteria.list();
		if(r.size()==0){
			return null;
		}else{
			return r.get(0);
		}
	}

	@Override
	public Comment getCommentByNotice(PictureNewsReceive pictureNewsReceive) {
		Criteria criteria = this.getSession().createCriteria(Comment.class);
		criteria.add(Restrictions.eq("pictureNewsReceive", pictureNewsReceive));
		List<Comment> r= criteria.list();
		if(r.size()==0){
			return null;
		}else{
			return r.get(0);
		}
	}

	@Override
	public Comment getCommentByNotice(AnnouncementReceive announcementReceive) {
		Criteria criteria = this.getSession().createCriteria(Comment.class);
		criteria.add(Restrictions.eq("announcementReceive", announcementReceive));
		List<Comment> r= criteria.list();
		if(r.size()==0){
			return null;
		}else{
			return r.get(0);
		}
	}

	@Override
	public Comment getCommentByNotice(NoticeAccept noticeAccept) {
		Criteria criteria = this.getSession().createCriteria(Comment.class);
		criteria.add(Restrictions.eq("noticeAccept", noticeAccept));
		List<Comment> r= criteria.list();
		if(r.size()==0){
			return null;
		}else{
			return r.get(0);
		}
	}

}
